import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
import url from '@/routers/home/router.js' 
const routes = [
  {
    path: "/",
    redirect: '/login'
  },
  {
    path: "/login",
    name: "login",
    component: () => import('../views/login.vue'),
  },
  {
    path: "/home",
    name: "home",
    component: () => import('../views/home.vue'),
    redirect:'/home/index',
    children: [
      ...url
    ]
  },
];

const router = new VueRouter({
  routes,
});

router.beforeEach((to, from, next) => {
  // console.log(to.path == '/login'); 
  if(to.path == '/login'){
    next()
  }else{
    if(JSON.parse(window.sessionStorage.getItem("user"))){
      next()
    }else{
    next('/')
    }
  }
})

export default router;
